package ciudadano;

import com.icesoft.faces.component.ext.HtmlInputSecret;
import com.icesoft.faces.component.ext.HtmlInputText;
import com.icesoft.faces.component.panelstack.PanelStack;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import javax.faces.FacesException;


public class GestionUsuario extends AbstractPageBean {

    private PanelStack panelStack = new PanelStack();
    private HtmlInputText inputTextDNI = new HtmlInputText();
    private HtmlInputText inputTextNombre = new HtmlInputText();
    private HtmlInputSecret inputSecret = new HtmlInputSecret();
    private HtmlInputText inputTextEmail = new HtmlInputText();

    private void _init() throws Exception
    {
    }




    public GestionUsuario() {
    }


    public String buttonAltaCiu_action() {
        if(comprobar())
        {
            try
            {
            ws.WebServiceIntermediadorService service = new ws.WebServiceIntermediadorService();
            ws.WebServiceIntermediador port = service.getWebServiceIntermediadorPort();

                ws.Usuario usuario = new ws.Usuario();
                usuario.setNif(inputTextDNI.getValue().toString());
                usuario.setPassword(inputSecret.getValue().toString());
                usuario.setNombre(inputTextNombre.getValue().toString());
                usuario.setEmail(inputTextEmail.getValue().toString());
                port.createUsuario(usuario);
            }
            catch (Exception ex)
            {
               ex.printStackTrace();
            }
        }
        return null;
    }


    private boolean comprobar()
    {
        if((inputTextDNI.getValue().toString().equals(""))||(inputTextEmail.getValue().toString().equals(""))
            ||(inputTextNombre.getValue().toString().equals(""))||(inputSecret.getValue().toString().equals("")))
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    @Override
    public void init()
    {
        super.init();

        try {
            _init();
        } catch (Exception e) {
            log("Operaciones Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }

    }


    @Override
    public void preprocess() {
    }

    @Override
    public void prerender() {
    }


    @Override
    public void destroy() {
    }

    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }


    public PanelStack getPanelStack() {
        return panelStack;
    }

    public void setPanelStack(PanelStack ps) {
        this.panelStack = ps;
    }

    public HtmlInputText getInputTextDNI() {
        return inputTextDNI;
    }

    public void setInputTextDNI(HtmlInputText hit) {
        this.inputTextDNI = hit;
    }

    public HtmlInputSecret getInputSecret() {
        return inputSecret;
    }

    public void setInputSecret(HtmlInputSecret his) {
        this.inputSecret = his;
    }

    public HtmlInputText getInputTextNombre() {
        return inputTextNombre;
    }

    public void setInputTextNombre(HtmlInputText inputTextNombre) {
        this.inputTextNombre = inputTextNombre;
    }

    public HtmlInputText getInputTextEmail() {
        return inputTextEmail;
    }

    public void setInputTextEmail(HtmlInputText hit) {
        this.inputTextEmail = hit;
    }



}

